﻿#ifndef WIDGET_H
#define WIDGET_H

#include "config.h"
#include "dialogsetting.h"
#include <QDebug>
#include <QDir>
#include <QSettings>
#include <QSystemTrayIcon>
#include <QWidget>
#include <QtMultimedia/QSound>

const int INTERVAL = 1000; //毫秒

QT_BEGIN_NAMESPACE
namespace Ui { class Widget; }
QT_END_NAMESPACE

class Widget : public QWidget
{
    Q_OBJECT

public:
    Widget(QWidget *parent = nullptr);
    ~Widget();
protected:
    void closeEvent(QCloseEvent *event) override;

private:
    Ui::Widget *ui;

    int curStep=0;
    int workSteps=50;
    int workStepsCopy=50;
    int breakSteps=10;
    int curPostoff=0;
    int postoffMax=2;
    int postoffSteps=2;

    DialogSetting *dialogSetting;

    QTimer *timer;

    QIcon icon=QIcon(":/assets/icons/tea-cup.png");

    QAction *restoreAction;
    QAction *quitAction;
    QAction *setAction;

    QSystemTrayIcon *trayIcon;
    QMenu *trayIconMenu;

    Config& config = Config::get_instance();

    QSound* bell;

    void createActions();
    void createTrayIcon();
    void createTimer();
    bool takeBreak();
    void takeBreakHard();
    void waitForCursorMove();
private slots:
    void iconActivated(QSystemTrayIcon::ActivationReason reason);
    void updateOneSec();
public slots:
    void updateConfig();
signals:
    void sendPlayBell();
};

#endif // WIDGET_H
